﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Common;

public partial class signin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1; 
    }
    protected void btnLogin_ServerClick(object sender, EventArgs e)
    {
        if ((txtPassword.Value.Trim() == "" || txtUsersName.Value.Trim() == ""))
        {
            loginMsg.InnerText = "* Username or password can not be empty!";
            return;
        }

        string password = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Value.Trim(), "md5");

        string result = BLL.SystemUserBase.ValidateUserLogin(txtUsersName.Value.Trim(), password);
        switch (result)
        {
            case "succeeded":
                HttpCookie myCookie = new HttpCookie("brighterfutureled_com");
                myCookie["Username"] = HttpUtility.UrlEncode(StringEncrypt.EncryptString(txtUsersName.Value.Trim()));
                myCookie.Expires = DateTime.Now.AddDays(5d);
                Response.Cookies.Add(myCookie);

                Response.Redirect("~/website_admin/_root/MainFrame.aspx");
                break;
            default:
                loginMsg.InnerText = "* 错误的用户名或密码！";  //"Invalid username or password. Please try again. ";
                break;
        }
    }
}
